package com.chilli.cosima.action.usermanager;

import java.util.List;

import com.chilli.cosima.action.BaseSupport;
import com.chilli.cosima.common.BussinessException;
import com.chilli.cosima.data.bean.TOperator;
import com.chilli.cosima.data.bean.TRole;
import com.chilli.cosima.service.UserService;
import com.chilli.cosima.utils.MD5Encrypt;

public class UserEditAction extends BaseSupport
{

	/**
	 * 注释内容
	 */
	private static final long serialVersionUID = -6764913130277169807L;

	private UserService userService;

	private Long id;

	private TOperator user;

	private List<TRole> roles;

	public List<TRole> getRoles()
	{
		return roles;
	}

	public void setRoles(List<TRole> roles)
	{
		this.roles = roles;
	}

	public String jumpPage()
	{

		TOperator user = (TOperator) userService.findUserById(id);

		if (null != user)
		{
			this.user = user;
			roles = userService.findAllRoles();
			return JUMP_PAGE;
		} else
		{
			logger.error("error");
			return ERROR;
		}

	}

	public String execute()
	{
		try
		{

			user.setLoginpwd(MD5Encrypt.encode(user.getLoginpwd()));
			user.setRolename(userService.findRoleNameById(user.getRoleid()));
			userService.updateUser(user);
		} catch (BussinessException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return SUCCESS;
	}

	public Long getId()
	{
		return id;
	}

	public void setId(Long id)
	{
		this.id = id;
	}

	public TOperator getUser()
	{
		return user;
	}

	public void setUser(TOperator user)
	{
		this.user = user;
	}

	public UserService getUserService()
	{
		return userService;
	}

	public void setUserService(UserService userService)
	{
		this.userService = userService;
	}

}
